<template>
  <Dialog
    :visible="addVisible"
    :title="title"
    :top="'25vh'"
    :width="480"
    @close="addVisible = false"
  >
    <div style="padding: 5px" v-if="addVisible" class="auditExam">
      <h1 v-if="title=='发药'">是否确定发药已完成！</h1>
      <h1 v-if="title=='驳回'">是否确定驳回当前发药单？</h1>



      <el-form :model="formData" label-width="70px" ref="ruleFormRef" v-if="title=='驳回'"  :labelPosition="'left'">
        <el-form-item label="备注：" prop="refuseReason">
          <el-input v-model="formData.refuseReason" placeholder="请输入" style="border: 1px solid #f5f7fa;" type="textarea" />
        </el-form-item>
      </el-form>
    </div>
    <template #footer>
      <!-- <el-checkbox v-model="checked" style="float:left;height: 32px;" v-if="title=='发药'" label="同步打印发药明细" size="large" /> -->
      <el-button @click="handleSubmit" type="primary">确 定</el-button>
    </template>

  </Dialog>
</template>

<script setup lang="ts">
import{rejectDelivery} from '@/api/exec';
const addVisible = ref(false);
import type { FormRules, ElTree } from 'element-plus';
const ruleFormRef = ref();


const checked = ref(false);
const title = ref('');
const formData = ref<any>({
  orderId: '',
  deliveryStatus: '',
  refuseReason: '',
});
defineExpose<{
  open: (type:number,orderId:any) => void;
}>({
  open: (type:number,orderId:any) => {
    formData.value.orderId = orderId;
    if(type == 3){
      title.value = '驳回'
    }else{
      title.value = '发药'
    }
    formData.value.deliveryStatus = type
    formData.value.refuseReason = ''
    addVisible.value = true;
  },
});

const handleSubmit = async () => {

      let res = await rejectDelivery(formData.value);
      if (res.code == '200') {
        ElMessage({
          type: 'success',
          message: res.msg,
        });
        closeDrawer();
      } else {
        
      }
};
const emit = defineEmits(['closeDrawer']);
const closeDrawer = () => {
  addVisible.value = false;
  emit('closeDrawer');
};
</script>
<style lang="scss">
    .auditExam .modal-footer{
      padding:  10px 0px;
    }
    .auditExam h1{
      font-size: 16px;
      
    }
</style>
<style lang="scss" scoped>
h1{
    font-family: Microsoft YaHei, Microsoft YaHei;
    font-weight: 400;
    font-size: var(--el-form-label-font-size);
    color: var(--el-text-color-regular);
    margin-bottom: 20px;
    text-align: left;
    font-style: normal;
    text-transform: none;
}</style>
